package main

import (
	"fmt"
	"reflect"
)

type Stud1 struct {
	Name string
	Age  int
}

func main() {
	Stud1 := Stud1{"zhangsan", 12}
	testReflectRes1(Stud1)
}

func testReflectRes1(a interface{}) {
	// 空接口接受
	typea := reflect.TypeOf(a)
	valuea := reflect.ValueOf(a)
	fmt.Printf("反射后的type: %T,%v; \n反射后的value: %T,%v\n", typea, typea, valuea, valuea)

	// 获取变量的类别
	k := typea.Kind()
	v := valuea.Kind()
	fmt.Printf("k类别为：%T, %v\n", k, k) //k类比为：reflect.Kind, struct
	fmt.Printf("v类别为：%T, %v\n", v, v) //v类比为：reflect.Kind, struct

	// 获取结构体类型
	realStud1 := valuea.Interface()
	n, flag := realStud1.(Stud1)
	if flag {
		fmt.Printf("找到了value的类型： %T, %v\n", n, n)
	}
}
